package com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.commandtype.infosecuritymanagement.illegalinfosecuritymanagement;

import com.zx.idc.backend.gui.api.commom.entity.CommandModel;
import com.zx.idc.backend.gui.api.management.infosecurity.violationwebsite.monitor.service.MonitorCommandService;
import com.zx.idc.backend.gui.api.management.infosecurity.violationwebsite.filter.service.FilterCommandService;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.CommandOperating;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.command.base.SubCommandHandler;
import com.zx.idc.backend.gui.api.ws.services.handler.strategy.entity.Option;
import com.zx.idc.xml.entity.command.Command;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import static com.zx.idc.common.attributes.SchemaFileNameAttributes.ILLEGAL_INFO_SECURITY_MANAGEMENT;

/**
 * Created by hasee on 2019/3/1.
 * 违法信息安全管理指令内容 11.7
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class IllegalInfoSecurityManagementImpl extends CommandOperating<Command> implements SubCommandHandler {

    private String schemaPath = getSchemaFilePath(ILLEGAL_INFO_SECURITY_MANAGEMENT);

    @Autowired
    private MonitorCommandService monitorCommandService;

    @Autowired
    private FilterCommandService filterCommandService;

    /**
     * 匹配方法
     *
     * @param xmlData
     * @return
     */
    @Override
    public boolean isMatch(String xmlData) {
        Command command = xml2Bean(xmlData, getFirstGenericClass(), schemaPath);
        return !ObjectUtils.isEmpty(command);
    }

    /**
     * 执行方法
     *
     * @param xmlData
     * @param commandModel
     * @return
     */
    @Override
    public String execute(String xmlData, CommandModel commandModel) {
        LOG.debug("信息管理指令执行");
        return receiveCommand(xmlData, commandModel, schemaPath);
    }

    /**
     * 覆盖该方法执行指令
     *
     * @param command      实体bean
     * @param commandModel 指令mode
     */
    @Override
    public void task(Command command, CommandModel commandModel) {
        //监控指令
        if (command.getType().equals(1)) {
            LOG.debug("调用监测指令处理服务");
            monitorCommandService.command(command, commandModel);

            //过滤指令
        } else if (command.getType().equals(2)) {
            LOG.debug("调用过滤指令处理服务");
            filterCommandService.command(command, commandModel);
        }
    }
}
